var job = [
    [
        [100, "战士"],
        [200, "魔法师"],
        [300, "弓箭手"],
        [400, "飞侠"],
        [500, "海盗"]
    ],
    [
        [1100, "魂骑士"],
        [1200, "炎术士"],
        [1300, "风灵使者"],
        [1400, "夜行者"],
        [1500, "奇袭者"]
    ],
    [
        [3200, "唤灵斗师"],
        [3300, "豹弩游侠"],
        [3500, "机械师"]
    ],
    [
        [110, "剑客"],
        [120, "准骑士"],
        [130, "枪战士"]
    ],
    [
        [210, "法师 (火/毒)"],
        [220, "法师 (冰/雷)"],
        [230, "牧师"]
    ],
    [
        [310, "猎人"],
        [320, "弩弓手"]
    ],
    [
        [410, "刺客"],
        [420, "侠客"]
    ],
    [
        [510, "拳手"],
        [520, "火枪手"]
    ]
];
var extra = true;
var status = -1;
var select;
var tempest = true;
var jobindex;

function start() {
    jobindex = null;
    select = null;
    status = -1;
    action(1, 0, 0)
}

function action(c, b, a) {
    if (c == 0 || c == -1 && status == 0) {
        cm.dispose();
        return
    } else {
        (c == 1 ? status++ : status--)
    }
    if (status == 0) {
        if ((cm.getPlayer().getLevel() >= 10 && (cm.getPlayer().getJob() % 1000 == 0 || cm.getPlayer().getJob() == 501 || cm.getPlayer().getJob() == 3001 || cm.getPlayer().getJob() >= 2001 && cm.getPlayer().getJob() <= 2003) || cm.getPlayer().getLevel() >= 30 && (cm.getPlayer().getJob() % 1000 > 0 && cm.getPlayer().getJob() % 100 == 0 || cm.getPlayer().getJob() == 508) || cm.getPlayer().getLevel() >= (tempest ? 60 : 70) && cm.getPlayer().getJob() % 10 == 0 && cm.getPlayer().getJob() % 100 != 0 || cm.getPlayer().getLevel() >= (tempest ? 100 : 120) && cm.getPlayer().getJob() % 10 == 1 || cm.getPlayer().getLevel() >= 20 && cm.getPlayer().getJob() == 400 && cm.getPlayer().getSubcategory() == 1 || cm.getPlayer().getLevel() >= 30 && cm.getPlayer().getJob() == 430 || cm.getPlayer().getLevel() >= (tempest ? 45 : 55) && cm.getPlayer().getJob() == 431 || cm.getPlayer().getLevel() >= (tempest ? 60 : 70) && cm.getPlayer().getJob() == 432 || cm.getPlayer().getLevel() >= (tempest ? 100 : 120) && cm.getPlayer().getJob() == 433) && (cm.getPlayer().getJob() % 10 != 2 && cm.getPlayer().getJob() % 10 != 4 || cm.getPlayer().getJob() == 432)) {
            if (isExplorer(cm.getPlayer().getJob())) {}
            cm.askYesNo("根据你现在的条件可以进行转职,你确定进行转职吗?")
        } else {
            cm.sendOk("根据你现在的条件还不能进行转职。\r\n追忆冒险岛转职详情：除冒险家,初心者,反抗者以外的职业全部为系统自动转职。");
            cm.dispose()
        }
    } else {
        if (status == 1) {
            if (cm.getPlayer().getSubcategory() == 1 && cm.getPlayer().getJob() == 0) {
                cm.getPlayer().changeJob(400);
                cm.dispose();
                return
            }
            if (cm.getPlayer().getSubcategory() == 1 && cm.getPlayer().getJob() == 400) {
                cm.getPlayer().changeJob(430);
                cm.dispose();
                return
            }
            if (cm.getPlayer().getSubcategory() == 10 && cm.getPlayer().getJob() == 0) {
                cm.getPlayer().changeJob(508);
                cm.getPlayer().forceChangeChannel(cm.getPlayer().getClient().getChannel());
                cm.dispose();
                return
            }
            if (cm.getPlayer().getSubcategory() == 2 && cm.getPlayer().getJob() == 0) {
                cm.getPlayer().changeJob(501);
                cm.dispose();
                return
            }
            switch (cm.getPlayer().getJob()) {
                case 0:
                    jobSelection(0);
                    break;
                case 1000:
                    jobSelection(1);
                    break;
                case 3000:
                    jobSelection(2);
                    break;
                case 100:
                    jobSelection(3);
                    break;
                case 200:
                    jobSelection(4);
                    break;
                case 300:
                    jobSelection(5);
                    break;
                case 400:
                    jobSelection(6);
                    break;
                case 500:
                    jobSelection(7);
                    break;
                case 501:
                    cm.getPlayer().changeJob(530);
                    cm.dispose();
                    return;
                case 508:
                    cm.getPlayer().changeJob(570);
                    cm.dispose();
                    return;
                case 2000:
                    cm.getPlayer().changeJob(2100);
                    cm.dispose();
                    return;
                case 2001:
                    cm.getPlayer().changeJob(2200);
                    cm.dispose();
                    return;
                case 2002:
                    cm.getPlayer().changeJob(2300);
                    cm.dispose();
                    return;
                case 2003:
                    cm.getPlayer().changeJob(2400);
                    cm.dispose();
                    return;
                case 2004:
                    cm.getPlayer().changeJob(2700);
                    cm.dispose();
                    return;
                case 3001:
                    cm.getPlayer().changeJob(3100);
                    cm.dispose();
                    return;
                case 5000:
                    cm.getPlayer().changeJob(5100);
                    cm.dispose();
                    return;
                case 6000:
                    cm.getPlayer().changeJob(6100);
                    cm.dispose();
                    return;
                case 6001:
                    cm.getPlayer().changeJob(6500);
                    cm.dispose();
                    return;
                case 430:
                case 431:
                case 432:
                case 433:
                    cm.getPlayer().changeJob(cm.getPlayer().getJob() + 1);
                    cm.dispose();
                    return;
                case 900:
                case 1100:
                case 1200:
                case 1300:
                case 1400:
                case 1500:
                case 2100:
                case 2300:
                case 2400:
                case 2700:
                case 3100:
                case 3200:
                case 3300:
                case 3500:
                case 5100:
                case 6100:
                case 6500:
                    cm.getPlayer().changeJob(cm.getPlayer().getJob() + 10);
                    cm.dispose();
                    return;
                case 110:
                case 120:
                case 130:
                case 210:
                case 220:
                case 230:
                case 310:
                case 320:
                case 410:
                case 420:
                case 510:
                case 520:
                case 530:
                case 570:
                case 1110:
                case 1210:
                case 1310:
                case 1410:
                case 1510:
                case 2110:
                case 2310:
                case 2410:
                case 2710:
                case 3110:
                case 3210:
                case 3310:
                case 3510:
                case 5110:
                case 6110:
                case 6510:
                case 111:
                case 121:
                case 131:
                case 211:
                case 221:
                case 231:
                case 311:
                case 321:
                case 411:
                case 421:
                case 511:
                case 521:
                case 531:
                case 571:
                case 1111:
                case 1211:
                case 1311:
                case 1411:
                case 1511:
                case 2111:
                case 2311:
                case 2411:
                case 2711:
                case 3111:
                case 3211:
                case 3311:
                case 3511:
                case 5111:
                case 6111:
                case 6511:
                    cm.getPlayer().changeJob(cm.getPlayer().getJob() + 1);
                    cm.dispose();
                    return;
                default:
                    cm.sendOk("好的,我已经帮你转职成 " + cm.getPlayer().getJob() + "了,祝您游戏愉快。");
                    cm.dispose();
                    return
            }
        } else {
            if (status == 2) {
                select = a;
                cm.askYesNo("你确定选择该职业,进行转职吗？\r\n一旦选择就无法更改了,请慎重选择。")
            } else {
                if (status == 3) {
                    if (select != 3100) {
                        cm.getPlayer().changeJob(getRealJob(select));
                        if (!specialSecondaryWeaponJob(getRealJob(select))) {
                            cm.dispose()
                        }
                        return
                    } else {
                        cm.askMenu("As a Demon Slayer, you will have to choose a #bDemon Marking#k.\r\n#L1012276##i1012276##l\r\n#L1012277##i1012277##l\r\n#L1012278##i1012278##l\r\n#L1012279##i1012279##l\r\n#L1012280##i1012280##l")
                    }
                    if (getSubcategory(select) != 0) {
                        cm.getPlayer().changeJob(getRealJob(select));
                        cm.getPlayer().setSubcategory(getSubcategory(select));
                        cm.getPlayer().dropMessage(0, "You will change channel now so the special job change will effect you. No worries, you will land on the same channel you were in before.");
                        cm.dispose();
                        return
                    }
                } else {
                    if (status == 4) {
                        cm.getPlayer().setDemonMarking(a);
                        cm.getPlayer().setSkinColor(4);
                        cm.getPlayer().changeJob(getRealJob(select));
                        if (select == 3100) {
                            cm.sendOk("As a Demon Slayer, your Mana Points(MP) will turn into Demon Force (DF) as soon as you log off.")
                        }
                        cm.dispose();
                        return
                    }
                }
            }
        }
    }
}

function jobSelection(a) {
    jobindex = a;
    var c = "#b请选择您要转入的职业:";
    for (var b = 0; b < job[a].length; b++) {
        c += "\r\n#L" + job[a][b][0] + "#" + job[a][b][1] + "#l"
    }
    cm.askMenu(c)
}

function getSubcategory(a) {
    switch (a) {
        case 9400:
        case 430:
        case 431:
        case 432:
        case 433:
        case 434:
            return 1;
        case 9501:
            return 2;
        case 9508:
            return 10
    }
    return 0
}

function getRealJob(a) {
    switch (a) {
        case 9400:
            return 400;
        case 9501:
            return 501;
        case 9508:
            return 508
    }
    return a
}

function specialSecondaryWeaponJob(a) {
    switch (a) {
        case 508:
        case 570:
        case 571:
        case 572:
        case 3001:
        case 3100:
        case 3110:
        case 3111:
        case 3112:
        case 5100:
        case 5110:
        case 5111:
        case 5112:
            return true
    }
    return false
}

function isExplorer(a) {
    return a / 1000 == 0
};